// pages/teacher/component/kaoqin/kaoqin.js
import {
  go_attend
} from '../../../../api/teacher.js'
import {
  finish
} from '../../../../api/teacher.js'

import {
  attend_sign
} from '../../../../api/teacher.js'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    banjiId: String,
    banjiCount: Number

  },

  /**
   * 组件的初始数据
   */
  data: {
    id: '',
    count: '',
    signlist: [],
    kqid: ''

  },
  observers: {
    banjiId(value) {
      console.log(value);
      this.setData({
        id: value

      })
      if (value === undefined) return
    },
    banjiCount(value) {
      console.log(value);
      this.setData({
        count: value

      })
    }

  },

  /**
   * 组件的方法列表
   */
  methods: {
    //  获取签到数据
    signdata() {
      let data = {
        id: this.data.id,
        count: this.data.count
      }
      console.log(data);
      attend_sign(data).then(res => {
        console.log(res);
        this.setData({
          signlist: res,
        })
      })
    },
    time_start() {
      this.signdata()
      let data = {
        id: this.data.id,
      }
      go_attend(data).then(res => {
        // console.log(res);
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      })
    },
    time_finish() {
      let data = {
        id: this.data.id
      }
      finish(data).then(res => {
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
        this.triggerEvent('timeout')
      })
    },
    attend_stu() {
      let data = {
        id: this.data.id,        
      }
      wx.navigateTo({
        url: '/pages/teacher/component/kaoqin/record',
        success: function (res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('emitid', data)
        }
      })
    }
  }
})